import React, { useContext, useState } from 'react';
import { MathContext } from './reducer';
import { ADD, SUB } from './constant';
function Buttons() {
  const { dispatch, constant, dispatch_1 } = useContext(MathContext);
  const [fudu, setFudu] = useState(constant);
  return (
    <>
      <p>当前增幅跌幅值为{constant}</p>
      <input
        type="text"
        onChange={e => {
          setFudu(e.target.value);
        }}
      />
      <button
        onClick={() => {
          let value = isNaN(Number(fudu)) ? 1 : Number(fudu);
          dispatch_1({ type: ADD, value });
        }}
      >
        修改增幅跌幅为{fudu}
      </button>
      <button
        onClick={() => {
          dispatch({ type: ADD, value: Number(fudu) });
        }}
      >
        加加加{fudu}
      </button>
      <button
        onClick={() => {
          dispatch({ type: SUB, value: Number(fudu) });
        }}
      >
        减减减{fudu}
      </button>
    </>
  );
}
export default Buttons;
